/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package grest.controller;

import grest.model.Entidad;
import grest.model.Mozos;
import grest.model.TableModelSL;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import grest.view.VistaBusqueda;
import java.util.List;
import java.util.Locale;
import java.util.Observable;
import javax.swing.JTable;

/**
 *
 * @author Agustin
 */
public class CntrlrVistaBusqueda  extends Observable implements ActionListener {
    private VistaBusqueda form;
    private JTable tablaBusqueda;
    private TableModelSL modelSL;
    
    
    public CntrlrVistaBusqueda(VistaBusqueda form){
        this.form = form;
        this.tablaBusqueda = (JTable)form.getControls("tblBusqueda");
        this.modelSL = (TableModelSL)tablaBusqueda.getModel();
    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==form.getControls("btnOk")){
            setObjetoSeleccionado();
        }
    }
    
    
    public void setObjetoSeleccionado(){
        Integer fila = this.tablaBusqueda.getSelectedRow();
        if (fila != -1){
            List<Entidad> arrayV =  modelSL.getModel();
            Entidad ent = arrayV.get(fila);
           // form.setObjetoSeleccionado(ent);
            setChanged();
            notifyObservers(ent);
            form.close();
        }
    }
    
}